import java.util.Arrays;
import java.util.Scanner;
public class Player{ 
    

    private static String name;
    private static String Class;
    private static int atk;
    private static int def;
    private static int mag;
    private static int mdef;
    private static int spe;
    private static int gold;
    private static int hp;
    private static int maxHp;
    private static int mp;
    private static int maxMp;
    private static int lv;
    private static int exp;
    private static int obj;
    private static Item[] inv;
    private static Item [] equipped;
    private static Scanner scan = new Scanner(System.in);
    private static String searchMe = "";

    public Player(String newName)
    {
        name = newName;
        Class = "bard";
        hp = 30;
        maxHp = hp;
        mp = 15;
        maxMp = mp;
        atk = 20;
        mag = 20;
        def = 15;
        mdef = 15;
        lv = 1;
        exp = 0;
        gold = 0;
        inv = new Item[20];
        equipped = new Item[6];
        obj = 0;
        
        // adjust for item array
        equipped[0].changeName("nothing");//left hand
        equipped[1].changeName("Lyre");// right hand
        equipped[2].changeName("[empty]");// head
        equipped[3].changeName("cotton shirt");//chest
        equipped[4].changeName("cotton pants");;//legs
        equipped[5].changeName("shoes"); // feet
        for(int c = 0; c < 19; c++)
        {
            inv[c].changeName("[empty]");
        }
    }
    
    public static void dispStats()
    {
        System.out.println(name + "\n============");
        System.out.println("Class      " + Class);
        System.out.println("Hp         " + hp + "/"+ maxHp);
        System.out.println("Lv         " + lv);
        System.out.println("Atk        " + atk);
        System.out.println("Def        " + def);
        System.out.println("Mag        " + mag);
        System.out.println("MDef       " + mdef);
        System.out.println("Spe        " + spe);
        System.out.println("Exp        " + exp);
        System.out.println("Gold       " + gold);
    }
    public void add(String item) {
    if(searchInv("[empty]"))
    {
        for (int c = 0; c <= 19; c++)
        {
            if (inv[c].name() == "[empty]")
            {
                inv[c].changeName(item);
                System.out.println(item + " has been added to your inventory");
                Parser.setParam("");
                return;
            }
        }
    }
    else
        System.out.println("You have no room");
    }
    public String getHands()
    {
        return equipped[0].name() + equipped[1].name();
    }
    public void getInv() {
        int place = 0;
        for (int r = 0; r < 4; r++) {
            for (int c = 0; c < 5; c++) {
                System.out.print(inv[place] + "\t");

                    place++;
            }
            System.out.println();
        }
    }
    public void getEquipped()
    {
        System.out.println("L Hand   /t"+equipped[0].name());
        System.out.println("R Hand   /t"+equipped[1].name());
        System.out.println("Head     /t"+equipped[2].name());
        System.out.println("Chest    /t"+equipped[3].name());
        System.out.println("Legs     /t"+equipped[4].name());
        System.out.println("Feet     /t"+equipped[5].name());
    }
    public static boolean searchInv(String item)
    {
        searchMe = "";
        for (int c = 0; c <= 19; c++)
        {
            searchMe += equipped[c].name();
            searchMe+="#";
        }
        if(searchMe.contains(item))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public static int findItem(String item)
    {
        Arrays.sort(inv);
        return Arrays.binarySearch(inv, item);
    }
    public void discard(String item) {
        Arrays.sort(inv);
        inv[Arrays.binarySearch(inv, item)].changeName("[empty]");
        System.out.println("You lost a " + item);
        Parser.setParam("");
    }
    public void gameOver()
    {
        //clear save file
        System.out.println("A man with a silver hook appears, cloaked in darkness");
        scan.nextLine();
        Sys.sp("Ya sane marethyu");
        Sys.delay(1);
        Sys.sp("I am death");
        Sys.delay(1);
        Sys.sp("I welcome thee");
        scan.nextLine(); 
        System.out.println("Game Over");
        credits();
        System.exit(0);
    }
    public static void credits()
    {
        Sys.sp("World design       Josh");
        Sys.delay(3);
        Sys.sp("Parser             Andrew");
        Sys.delay(3);
        Sys.sp("Storyline          Loki");
        Sys.delay(3);
        Sys.sp("Battle design      Nickname");
        Sys.delay(3);
        Sys.sp("Mob design         Mojang");
        Sys.delay(3);
        Sys.sp("Title              Snow White");
        Sys.delay(3);
        Sys.sp("Player             " + name);
        Sys.delay(3);
        Sys.sp("Time Extension     Mr. Echols");
        Sys.delay(3);
        Sys.sp("Sacrifice          TMAC");
        Sys.delay(3);
        Sys.sp("Attempted Failure  The Fourth Age");
        Sys.delay(3);
        Sys.sp("Credits Reader     "+ name);
        Sys.delay(3);
        Sys.sp("Thanks for Playing -Josh and Andrew");
        Sys.delay(3);
    }
    public static String getLeft()
    {
        return equipped[0].name();
    }
    public static String getRight()
    {
        return equipped[1].name();
    }
    public static String getHead()
    {
        return equipped[2].name();
    }
    public static String getChest()
    {
        return equipped[3].name();
    }
    public static String getLegs()
    {
        return equipped[4].name();
    }
    public static String getFeet()
    {
        return equipped[5].name();
    }
    public static void equip(String name)
    {
        if(searchInv(name))
        {
            Item temp = new Item(name);
            switch(temp.type())
            {
                case "hand":
                    System.out.print("Which hand?\n/");
                    String hand = scan.nextLine();
                    switch(hand.toLowerCase().trim())
                    {
                        case "l": case "left":
                            inv[Arrays.binarySearch(inv , name)].changeName(equipped[0].name());
                            equipped[0].changeName(temp.name());
                            break;
                        case "r": case "right":
                            inv[Arrays.binarySearch(inv , name)].changeName(equipped[1].name());
                            equipped[1].changeName(temp.name());
                            break;
                        default:
                            System.out.println("Thats not a hand");
                            break;
                    }
                    break;
                case "head":
                    inv[Arrays.binarySearch(inv , name)].changeName(equipped[2].name());
                    equipped[2].changeName(temp.name());
                    break;
                case "chest":
                    inv[Arrays.binarySearch(inv , name)].changeName(equipped[3].name());
                    equipped[3].changeName(temp.name());
                    break;
                case "legs":
                    inv[Arrays.binarySearch(inv , name)].changeName(equipped[4].name());
                    equipped[4].changeName(temp.name());
                    break;
                case "feet":
                    inv[Arrays.binarySearch(inv , name)].changeName(equipped[5].name());
                    equipped[5].changeName(temp.name());
                    break;
                default:
                    System.out.println("You cant equip that");
                    break;
            }
        }
        else
        {
            System.out.println("You dont have one to equip");
        }
    }
    public static void newObj()
    {
        obj++;
        System.out.println("New Objective: " + getObj());
    }
    public static String getObj()
    {
        switch(obj)
        {
            case 1: 
                return "Go to the lab";
            case 2:
                return "Go save the world";
            default:
                return "Go fuck yourself";
        }
    }
    public static void itemInfo(int itemNum)
    {
        inv[itemNum].descript();
    }
    public static void healHp (int ammount)
    {if(hp + ammount < maxHp)
    {
        hp+= ammount;
        System.out.println("You regained " + ammount + " hp.");
    }
    else
    {
        hp = maxHp;
        System.out.println("Your hp was fully restored.");
    }
    }
    public static void healMp (int ammount)
    {if(mp + ammount < maxMp)
        {
            mp+= ammount;
            System.out.println("You regained " + ammount + " mp.");
        }
        else
        {
            mp = maxMp;
            System.out.println("Your mp was fully restored.");
        }
    }
}
